package org.apache.zookeeper.server.paxos2;

import java.nio.ByteBuffer;

public class BlockMeta {
	public static final int BLOCK_META_SIZE = 16;
	public long zxid;
	public int clientId;
	public int cxid;
	
	public BlockMeta(){}
	
	public BlockMeta(long zxid, int clientId, int cxid){
		this.zxid = zxid;
		this.clientId = clientId;
		this.cxid = cxid;
	}
	
	public BlockMeta(ByteBuffer b){
		this.zxid = b.getLong();
		this.clientId = b.getInt();
		this.cxid = b.getInt();
	}
	
	public void deserialize(ByteBuffer b){
		this.zxid = b.getLong();
		this.clientId = b.getInt();
		this.cxid = b.getInt();
	}
	
	public void serialize(ByteBuffer b){
		b.putLong(zxid);
		b.putInt(clientId);
		b.putInt(cxid);
	}
	
	public byte[] toByteArray(){
		byte[] ret = new byte[BLOCK_META_SIZE];
		ByteBuffer b = ByteBuffer.wrap(ret);
		b.putLong(zxid);
		b.putInt(clientId);
		b.putInt(cxid);
		return ret;
	}

	public String toString(){
		return "v"+zxid+" ID("+clientId+" "+cxid+")";
	}

}
